#include <string.h>
#include <math.h>
#include <iostream>
using std::cout;
using std::endl;

class Point
{
public:
    Point(float x,float y)
    : _x(x)
    , _y(y)
    {}
    friend class Line;
private:
    float _x;
    float _y;
};

class Line
{
public:
    Line(const Point & lhs,const Point & rhs)
    : _pt1(lhs)
    , _pt2(rhs)
    {}

    Line(int x1,int y1,int x2,int y2)
    : _pt1(x1,y1)
    , _pt2(x2,y2)
    {}

    float distance() const{
        return sqrt(pow(_pt1._x - _pt2._x, 2) 
                    + pow(_pt1._y - _pt2._y, 2) );
    }

private:
    Point _pt1;
    Point _pt2;
};

class Color
{
public:
    Color(const char * cl)
    : _color(new char[strlen(cl)]())
    {
        strcpy(_color,cl);
    }

    ~Color(){
        if(_color){
            delete [] _color;
        }
    }

    Color(const Color & rhs)
    : _color(new char[strlen(rhs._color)]())
    {
        strcpy(_color,rhs._color);
    }

    Color & operator=(const Color & rhs){
        if(this != &rhs){
            delete [] _color;
            _color = new char[strlen(rhs._color) + 1](); 
            strcpy(_color,rhs._color);
        }
        return *this;
    }

    void showColor() const{
        cout << "颜色:" << _color << endl;
    }
private:
    char * _color;
};

class Triangle
: public Line
, public Color
{
public:
    Triangle(const Point & p1,const Point & p2,
             const char * color,float height)
    : Line(p1,p2)
    , Color(color)
    , _height(height)
    {}

    Triangle(int x1,int y1,int x2,int y2,
             const char * color,float height)
    : Line(x1,y1,x2,y2)
    , Color(color)
    , _height(height)
    {}

    float getPerimeter() const{
        float x = distance();
        float z = sqrt(x * x + _height * _height);
        return x + _height + z; 
    }

    float getArea() const{
        float x = distance();
        return x * _height / 2;
    }

    void show() const{
        showColor();
        cout << "周长:" << getPerimeter() << endl;
        cout << "面积:" << getArea() << endl;
    }
    
private:
    float _height;
};

void test0(){
    Triangle t1(0,0,0,3,"Red",4);
    t1.show();

    cout << endl;
    Point p1(0,0);
    Point p2(12,0);
    Triangle t2(p1,p2,"Green",5);
    t2.show();
}

int main(void){
    test0();
    return 0;
}

